#version 450
#define SM_LIGHTTYPE_DIRECTIONALLIGHT
#define SM_FLOAT 1
#define SM_ESM 1
#define SM_DEPTHTEXTURE 0
#define SM_NORMALBIAS 0
#define SM_DIRECTIONINLIGHTDATA 1
#define SM_USEDISTANCE 0
#define SM_SOFTTRANSPARENTSHADOW 1
#define ALPHATEXTURE
#define ALPHATESTVALUE 0.4
#define UV1
#define NUM_BONE_INFLUENCERS 0
#define SHADER_NAME fragment:shadowMap
layout(set = 1, binding = 4) uniform LeftOver {
        mat4 diffuseMatrix;
    vec3 biasAndScaleSM;
    vec2 depthValuesSM;
    float softTransparentShadowSM;
};

precision highp float;
// Internals UBO
layout(set = 1, binding = 0) uniform Internals {
float yFactor_;
float textureOutputHeight_;
};
vec4 glFragCoord_;

float bayerDither2(vec2 _P) {return mod(2.0*_P.y+_P.x+1.0,4.0);
}
float bayerDither4(vec2 _P) {vec2 P1=mod(_P,2.0);
vec2 P2=floor(0.5*mod(_P,4.0));
return 4.0*bayerDither2(P1)+bayerDither2(P2);
}
float bayerDither8(vec2 _P) {vec2 P1=mod(_P,2.0);
vec2 P2=floor(0.5 *mod(_P,4.0));
vec2 P4=floor(0.25*mod(_P,8.0));
return 4.0*(4.0*bayerDither2(P1)+bayerDither2(P2))+bayerDither2(P4);
}

layout(location = 1)  in float vDepthMetricSM;


layout(location = 0)  in vec2 vUV;
layout(set = 1, binding = 3) uniform sampler diffuseSamplerSampler;
                        layout(set = 1, binding = 2) uniform texture2D diffuseSamplerTexture;
                        #define diffuseSampler sampler2D(diffuseSamplerTexture, diffuseSamplerSampler)
#define CUSTOM_FRAGMENT_DEFINITIONS
layout(location = 0) out vec4 glFragColor;
void main(void)
{
                glFragCoord_ = gl_FragCoord;
                if (yFactor_ == 1.) {
                    glFragCoord_.y = textureOutputHeight_ - glFragCoord_.y;
                }
            
float alphaFromAlphaTexture=texture(diffuseSampler,vUV).a;
if (alphaFromAlphaTexture<ALPHATESTVALUE)
discard;
if ((bayerDither8(floor(mod(glFragCoord_.xy,8.0))))/64.0>=softTransparentShadowSM*alphaFromAlphaTexture) discard;
float depthSM=vDepthMetricSM;
depthSM=clamp(exp(-min(87.,biasAndScaleSM.z*depthSM)),0.,1.);
glFragColor=vec4(depthSM,1.0,1.0,1.0);
return;
}